package com.suitsoft.ut.entity.base;

import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.google.common.collect.Lists;
import com.suitsoft.ut.entity.IdEntity;
import com.suitsoft.ut.entity.account.Role;
import com.suitsoft.ut.entity.account.User;

/**
 * 团队
 *@author Suineg
 */
@Entity
@Table(name = "LW_GROUP")
public class Team extends IdEntity{
	/** 学院  */
	private College college;
	/** 团队名 */
	private String groupName;
	/** 操作人 */
	private User lastUser;
	/** 类型 1 - 立题，2 - 审题,3 - 答辩 */
	private String type;
	/** 上级 */
	private Team subTeam;
	/** 团队负责人 */
	private Teacher master;
	/** 学生 */
	private List<Student> students = Lists.newArrayList(); 
	/** 答辩时间 */
	private Date dabianDate;
	/** 答辩地址 */
	private String dabianAddress;
	/** 最后操作时间 */
	private Date lastDate;
	/** 所有下级 */
	
	private Set<Team> teamSet = new HashSet<Team>();
	
	/** 教师 */
	
	private List<Teacher> teacherList = Lists.newArrayList();
	//多对多定义
	@ManyToMany
	//中间表定义,表名采用默认命名规则
	@JoinTable(name = "LW_TEACHER_GROUP", joinColumns = { @JoinColumn(name = "GROUP_ID") }, inverseJoinColumns = { @JoinColumn(name = "TEACHER_ID") })
	//Fecth策略定义
	@Fetch(FetchMode.SUBSELECT)
	//集合按id排序.
	@OrderBy("id")
	//集合中对象id的缓存.
	@Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE)
	public List<Teacher> getTeacherList() {
		return teacherList;
	}
	public void setTeacherList(List<Teacher> teacherList) {
		this.teacherList = teacherList;
	}
	@OneToMany(fetch = FetchType.LAZY,mappedBy = "subTeam")
	public Set<Team> getTeamSet() {
		return teamSet;
	}
	public void setTeamSet(Set<Team> teamSet) {
		this.teamSet = teamSet;
	}
	@OneToMany(fetch = FetchType.LAZY,mappedBy="group")
	@OrderBy("studentNo")
	public List<Student> getStudents() {
		return students;
	}
	public void setStudents(List<Student> students) {
		this.students = students;
	}

	/** 权限 */
	private Role role;
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "COLLEGE_ID")
	public College getCollege() {
		return college;
	}
	public void setCollege(College college) {
		this.college = college;
	}
	public String getGroupName() {
		return groupName;
	}
	public void setGroupName(String groupName) {
		this.groupName = groupName;
	}
	@ManyToOne(fetch =FetchType.LAZY)
	@JoinColumn (name = "USER_ID")
	public User getLastUser() {
		return lastUser;
	}
	public void setLastUser(User lastUser) {
		this.lastUser = lastUser;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "SUB_ID")
	public Team getSubTeam() {
		return subTeam;
	}
	public void setSubTeam(Team subTeam) {
		this.subTeam = subTeam;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "ROLD_ID")
	public Role getRole() {
		return role;
	}
	public void setRole(Role role) {
		this.role = role;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "MASTER_ID")
	public Teacher getMaster() {
		return master;
	}
	public void setMaster(Teacher master) {
		this.master = master;
	}
	public Date getDabianDate() {
		return dabianDate;
	}
	public void setDabianDate(Date dabianDate) {
		this.dabianDate = dabianDate;
	}
	public String getDabianAddress() {
		return dabianAddress;
	}
	public void setDabianAddress(String dabianAddress) {
		this.dabianAddress = dabianAddress;
	}
	public Date getLastDate() {
		return lastDate;
	}
	public void setLastDate(Date lastDate) {
		this.lastDate = lastDate;
	}
}

